﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Laos.Weaver;
using PostSharp.Extensibility;
using CyclicReferences.Public;

namespace CyclicReferences.Weaver
{
    /// <summary>
    /// returns the correct weaver. In this case, always the weaver for creating surrogate classes
    /// </summary>
    public class WeaverFactory : Task, ILaosAspectWeaverFactory
    {

        #region ILaosAspectWeaverFactory Members
        /// <summary>
        /// creates the weaver
        /// </summary>
        /// <param name="aspect">the EDMAttributesSubAspect that instantiated this factory</param>
        /// <returns>the weaver that will do the lowlever hardcore work</returns>
        public LaosAspectWeaver CreateAspectWeaver(PostSharp.Laos.ILaosAspect aspect)
        {
            if (aspect is CreateSerializeSurrogateAttribute)
            {
                CreateSerializeSurrogateAttribute createSurrogateAspect = (CreateSerializeSurrogateAttribute)aspect;
                return new Weaver(createSurrogateAspect.OriginalValueProvider);
            }

            return null;
        }

        #endregion
    }
}
